package com.admin.education.dataTransferObject.userRecord.Mapper;

import com.admin.education.dataTransferObject.userRecord.UserRecordTransfer;
import com.admin.education.models.UserRecords;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.Mappings;

import java.util.List;

@Mapper
public abstract class UserRecordMapper {
    @Mappings({})
    public abstract UserRecordTransfer mapFrom(UserRecords userRecords);

    @Mappings({})
    public abstract List<UserRecordTransfer> mapFrom(List<UserRecords> userRecords);

    @AfterMapping
    public void afterMapping(UserRecords userRecords, @MappingTarget UserRecordTransfer userRecordTransfer) {
        if (null != userRecords.getUserInformation()) {
            userRecordTransfer.setName(userRecords.getUserInformation().getName());
            if (null != userRecords.getUserInformation().getClasses()) {
                userRecordTransfer.setClassName(userRecords.getUserInformation().getClasses().getName());
            }
            if (null != userRecords.getUserInformation().getSchools()) {
                userRecordTransfer.setSchoolName(userRecords.getUserInformation().getSchools().getName());
            }
            if (null != userRecords.getUserInformation().getClasses().getGrades()) {
                userRecordTransfer.setGradeName(userRecords.getUserInformation().getClasses().getGrades().getName());
            }
        }
    }
}
